﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Store.DateModel;

public partial class Pages_WebControls_ProductMini : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    private int productID;
    public string ProductID
    {
        get { return productID + ""; }
        set
        {
            productID = Convert.ToInt32(value);
            if (!String.IsNullOrEmpty(Name))
            {
                UrlLink();
            }
        }
    }

    public string Name
    {
        get { return _LinkName.Text; }
        set
        {
            _LinkName.Text = value;
            if (!String.IsNullOrEmpty(ProductID))
            {
                UrlLink();
            }
        }
    }


    public string ImageUrl
    {
        get { return _LinkImage.Text; }
        set
        {
            if (value.Length > 0)
            {
                _Image.ImageUrl = Page.ResolveUrl(value);
            }
            else
            {
                _Image.ImageUrl = Page.ResolveUrl("~/Content/SiteImages/NoPictre.png");
            }
        }
    }


    public decimal Price
    {
       // get { return _Price.Text; }
        set { _Price.Text = String.Format("{0:0,0.##} RON", value); }
    }


    public decimal OldPrice
    {
       // get        {            return _OldPrice.Text;        }
        set
        {
            var oldprice = value;
            if (oldprice != 0)
            {
                _OldPrice.Text = String.Format("{0:0,0.##} RON", value);
            }
            else
            {
                _OldPrice.Text = "";
            }
        }
    }
    private void UrlLink()
    {
        var url = Page.GetRouteUrl("ProductDetails", new { id = ProductID, prodName = Name }).Replace("%20", "_");
        _LinkImage.NavigateUrl = url;
        _LinkName.NavigateUrl = url;
    }
}